#pragma once

#include <TFT_eSPI.h>
class TFTHandle
{
public:
    TFTHandle();
    void init();
    void drawImg(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t *img);
    void setLight(uint8_t pwmVal);
    void setBKI(uint16_t w, uint16_t h, uint16_t *img);
    void drawBKI();
    uint8_t getTemp(void);
    uint8_t getWind(void);
    uint8_t getStatus(void);
    uint8_t getMode(void);
    bool getTouch(uint16_t *x, uint16_t *y);
    void changeMode(uint8_t flag);
    void changeWind(uint8_t level);
    void changeTemp(uint8_t temp_value);
    void changeCNWSD(float temp, uint8_t humi);
    void close(void);
    void open(void);
private:
    TFT_eSPI TFT = TFT_eSPI();
    TFT_eSprite eSprite = TFT_eSprite(&TFT);
    uint16_t calibrationData[5] = {305, 3582, 222, 3625, 7}; // 触屏校准数据
    uint16_t *BKImage = nullptr;
    uint16_t BKImage_w;
    uint16_t BKImage_h;
    uint16_t icon_w = 80;    // 图标宽度
    uint16_t icon_h = 80;    // 图标高度
    uint16_t mode_x = 260;   // 模式图标x坐标
    uint16_t mode_y = 140;   // 模式图标y坐标
    uint16_t wind_x = 380;   // 风速图标x坐标
    uint16_t wind_y = 140;   // 风速图标y坐标
    uint16_t temp_x = 0;     // 温度x坐标
    uint16_t temp_y = 100;   // 温度y坐标
    uint16_t tempp_x = 270;  // 温度+x坐标
    uint16_t tempp_y = 260;  // 温度+y坐标
    uint16_t temps_x = 400;  // 温度-x坐标
    uint16_t temps_y = 260;  // 温度-y坐标
    uint8_t mode_flag = 0;   // 0-制暖 1-制冷 2-除湿
    uint8_t wind_level = 0;  // 0-自动 1-低风 2-中风 3-高风
    uint8_t temp_value = 27; // 温度值
    uint8_t work_state = 1; // 工作状态 1-开机 0-关机
};

extern TFTHandle tft;